export const isAndroid = (userAgent: string = navigator.userAgent) =>
  userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1; // android终端
export const isiOS = (userAgent = navigator.userAgent) =>
  !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
export const isWeChat = (userAgent = navigator.userAgent) =>
  userAgent.indexOf('MicroMessenger') !== -1; // wechat终端
export const isIE = () => !!window.ActiveXObject || 'ActiveXObject' in window;
export const isValidURL = (url: string) => {
  let v = new RegExp(
    '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
    'i',
  );
  return v.test(url);
};
